package cate.game.play.skill.passive.boss;

import cate.game.play.buff.Buff;
import cate.game.play.config.PlayCfgArgs;
import cate.game.play.proce.action.ctx.ActionCtx;
import cate.game.play.proce.action.ctx.SkillActionCtx;
import cate.game.play.proce.move.AppendMove;
import cate.game.play.proce.move.AppendMoveHandler;
import cate.game.play.proce.turn.TurnCtx;
import cate.game.play.skill.Skill;
import cate.game.play.skill.passive.PassiveHandler;

/**
 * 蚩尤被攻击时，会获得[混沌印记]无冷却时间 层数达到15层时释放[魔火焚世]，并清空[混沌印记]
 */
public class 魔劲激发PH extends PassiveHandler implements AppendMoveHandler {

	private int buff;

	private int 层数;

	private int 追加技能;

	//buff=？？&层数=15&追加技能=？？
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		buff = args.getInt("buff", 0);
		层数 = args.getInt("层数", 0);
		追加技能 = args.getInt("追加技能", 0);
	}

	private Skill appendSkill;

	@Override
	public void onFirstEnter(ActionCtx action) {
		for (Skill s : skill.owner.skill.getAllActive()) {
			if (s.tid == 追加技能) {
				appendSkill = s;
				break;
			}
		}
	}

	@Override
	public void onOwnerAddBuff(ActionCtx action, Buff addBuff) {
		if (addBuff.tid != buff) {
			return;
		}
		if (appendSkill == null) {
			return;
		}
		if (!(action instanceof SkillActionCtx)) {
			return;
		}
		SkillActionCtx skillAction = (SkillActionCtx) action;
		int count = skill.owner.buff.countBuffByTid(buff);
		if (count >= 层数) {
			AppendMove append = new AppendMove(skill.owner, appendSkill, this);
			skillAction.getTurn().addAppend(append);
		}
	}

	@Override
	public void afterSufferOneAttack(SkillActionCtx action, long totalDamage, boolean strike) {
		skill.owner.buff.tryAddByTid(action, buff);

	}

	@Override
	public boolean inValid(TurnCtx turn, AppendMove appendMove) {
		return false;
	}

	@Override
	public void beforeAppendMove(TurnCtx turn, AppendMove appendMove) {

	}

	@Override
	public void afterAppendMove(TurnCtx turn, AppendMove appendMove) {
		skill.owner.buff.removeBuff(turn.buildTimeAction(), b -> b.tid == buff);
	}

	@Override
	public void onAppendMoveFail(TurnCtx turn, AppendMove appendMove) {

	}
}
